#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

class RandomSet{
    public:
    RandomSet(){}

    bool insert(int val){
        int length = num.size();
        if(length == 0){
            num.push_back(val);
            return true;
        }else{
            for(int i = 0; i != length; i++){
                if(num[i] == val){
                    return false;
                }
            }
            num.push_back(val);
            return true;
        }  
    }

    bool remove(int val){
        int length = num.size();
        for(int i = 0; i != length; i++){
            if(num[i] == val){
                // for(int j = i; j <= length-1; j++){
                //     int temp = num[j];
                //     num[j] = num[j+1];
                //     num[j+1] = temp;
                // }
                // num.pop_back();
                num.erase(num.begin() + i); //使用迭代器
                return true;
            }
        }
        return false;
    }

    int getRandom(){
        srand((unsigned int)time(NULL));
        int length = num.size();
        int index = rand() % length;
        return num[index];
    }

    void show(){
        int length = num.size();
        for(int i = 0; i != length; i++){
            cout << num[i] << " " << ends;
        }
        cout << endl;
    }
    private:
    // unordered_map<int, int> hash;
    vector<int> num;
};

void test(){
    RandomSet* r = new RandomSet();
    cout << r->insert(1) << endl;
    r->show();
    cout << r->remove(2) << endl;
    r->show();
    cout << r->insert(2) << endl;
    r->show();
    cout << r->getRandom() << endl;
    r->show();
    cout << r->remove(1) << endl;
    r->show();
    cout << r->insert(2) << endl;
    r->show();
    cout << r->getRandom() << endl;
    r->show();

}

int main(void){
    test();

    return 0;
}